ans = 0
list = [1, 2, 3, 4, 5]
for i in list:
    ans += i
result = sum(list)

ans = 1
list = [1, 2, 3, 4, 5]
for i in list:
    ans *= i

result = max(list)

curr_min = list[0]
list = [1, 2, 3, 4, 5]
for i in list:
    if i < curr_min:
        curr_min = i
result = min(list)

'''
Write a Python program to count the number of strings where the string 
length is 2 or more and the first and last character are same from a given list of strings.
'''
strings = ["HoH", "WoW", "LL", "AB", "ABC"]
# 0. 初始的计数变量 = 0
# 1. 遍历 strings 中的每一个元素 s
# 2. 如果 s 满足题目中的要求
# 3. 计数变量 + 1
def match_strings(strings: list[str]) -> int:
  n = 0

  for i in strings:
    if len(i) > 1 and i[0] == i[-1]:
      n += 1
  return n

print(match_strings(['abc', 'xyz', 'aba', '1221']))

'''
Given an integer array nums sorted in non-decreasing order, 
return an array of the squares of each number sorted in non-decreasing order.

[1, 2, 3, 4, 5]
[1, 4, 9, 16, 25]

[-5, -4, -3, -2, -1]
[25, 16, 9, 4, 1]

[-3, -2, -1, 0, 1, 2]
[9, 4, 1, 0, 1, 4]

Caution: Squaring each element and sorting the new array is not recommended. 
You should find a new way to solve this problem.
                vR
[-3, -2, -1, 0, 1, 2] 排序好的平方数列表
     ^L

result
[0, 0, 0, 0, 0, 0]
-len(nums)
[0, 1, 1, 4, 4, 9]
                -1
'''
def squared_sorted(nums: list[int]) -> list[int]:
    result = [0] * len(nums)
    l = 0
    r = len(nums) - 1

    # Fill the result from right to left
    for i in range(-1, -len(nums) - 1, -1):
        if nums[l] * nums[l] >= nums[r] * nums[r]:
            result[i] = nums[l] * nums[l]
            l += 1
        else:
            result[i] = nums[r] * nums[r]
            r -= 1
    
    return result

'''
                 vR              
[-5, -4, -3, -2, -1]
                    ^L
result
[1, 4, 9, 16, 25]
'''

# 当我们要从右向左遍历一个列表的时候
nums = [-5, -4, -3, -2, -1]
for i in range(-1, -len(nums) - 1, -1):

print(squared_sorted(nums = [-5, -4, -3, -2, -1]))

def sortedSquares(A: list[int]) -> list[int]:
    for i in range(len(A)):
        A[i] *= A[i]
    A.sort()
    return A

def duplicateZeros(self, arr: list[int]) -> None:
    zeroes = arr.count(0)
    n = len(arr)
    for i in range(n-1, -1, -1):
        if i + zeroes < n:
            arr[i + zeroes] = arr[i]
        if arr[i] == 0: 
            zeroes -= 1
        if i + zeroes < n:
            arr[i + zeroes] = 0